package com.dyl.t01_juc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 描述：创建线程三种方式
 * 类名称：MultiThreadCreate
 * 创建人: daiyuling
 * 创建时间: 2025/10/13
 */
public class MultiThreadCreate {
    public static void main(String[] args){
        // 1. 继承Thread类
        new Thread01().start();
        // 2. 实现Runnable接口
        new Thread(new Thread02()).start();
        // 3. 实现Callable接口（配合futureTask使用）
        FutureTask<String> futureTask = new FutureTask<>(new Thread03());
        new Thread(futureTask).start();
        String s = null;
        try {
            s = futureTask.get();
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException(e);
        }
        System.out.println(s);
    }
}

class Thread01 extends Thread {
    @Override
    public void run() {
        System.out.println("多线程创建方式01");
    }
}

class Thread02 implements Runnable {
    @Override
    public void run() {
        System.out.println("多线程创建方式02");
    }
}

class Thread03 implements Callable<String> {
    @Override
    public String call() throws Exception {
        return "多线程创建方式03";
    }
}
